package com.qf.zyh.services.Impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.qf.zyh.dao.EmpMapper;
import com.qf.zyh.entity.Emp;
import com.qf.zyh.services.EmpServices;
import com.qf.zyh.util.StringUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
@Service
public class EmpServicesImpl implements EmpServices {
    @Autowired
    private EmpMapper em;

    @Override
    public Emp login(String name, String pwd) {
        if (StringUtil.nowEmpSize(name,pwd)) {
            Emp emp = em.getEmpEname(name);
            if (emp!=null){
                if (emp.getPwd().equals(pwd)) {
                    return emp;
                }
            }
        }
        return null;
    }

    @Override
    public boolean insertEmp(Emp e) {
        if (e!=null) {
            if (em.insertEmp(e)>0) {
                return true;
            }
        }
        return false;
    }

    @Override
    public boolean updateEmp(Emp e) {
        if (e!=null) {
            if (em.updateEmp(e)>0) {
                return true;
            }
        }
        return false;
    }

    @Override
    public boolean deleteEmoByEno(Integer eno) {
            if (em.deleteEno(eno)>0) {
                return true;
            }
        return false;
    }

    @Override
    public List<Emp> getAll() {
        return em.getAll();
    }

    @Override
    public Emp getEmpByEno(Integer eno) {
        Emp empEno = em.getEmpEno(eno);
        if (empEno!=null) {
            return empEno;
        }
        return null;
    }

    @Override
    public PageInfo<Emp> getEmpByPage(Integer pageindex) {
        PageHelper.startPage(pageindex,5);
        List<Emp> all = em.getAll();
        PageInfo<Emp> pageInfo = new PageInfo<>(all);
        return pageInfo;
    }
}
